<?php
class LCategorySourceMessage extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'LCategorySourceMessage';
    }

    public function rules()
    {

        return array(
                array('c', 'required'),
                array('c', 'length', 'max'=>10),
                array('id, c', 'safe', 'on'=>'search'),
        );
    }

    public function relations()
    {
        return array(
                'lSourceMessages' => array(self::HAS_MANY, 'LSourceMessage', 'category'),
        );
    }

    public function attributeLabels()
    {
        return array(
                'id'    => 'ID',
                'c'     => Yii::t('language', 'Категория меток словаря'),
        );
    }

    public static function dropDownItemsAll(){
        $items= Array();
        $model = self::model()->findAll();
        foreach ($model as $value) {
            $items[$value->id] = $value->c;
        }
        return $items;
    }

    public function search()
    {	
        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('c',$this->c,true);

        return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
        ));
    }
}